capture log close

set more off
set matsize 10000

use rep_final, clear

	*noncitizens
	keep if cit==0
	
	
	*ACS spouse characteristics include cohabiting couples, 
	*which is why unmarried can have spouse character.
	

	*examine ratio within cohabiting couples
	keep if related==1114


	*Define cohabiting spouse who is a citizen, out of the population
	g cohabit_cit_sp = 0
		replace cohabit_cit_sp = 1 if ((citizen_sp==2 & bpl_sp >120)  /// /*foreign born naturalized citizen*/
						  |(bpl_sp <=120 | citizen_sp==1  ))         /// /*native born or born abroad of american parents/
						  & marst>2 & citizen_sp!=. & related==1114  /*not married, cohabiting*/
	
	tab cohabit_cit_sp
	
	* Use this condition only when examining ratio within cohabiting couples
	*spouse info is avail.
	drop if citizen_sp==.


* Define control variables 

	local demog "age age2 male yreduc i.racegr"
	local imm "ysm i.bpl " 
	*cannot use yrmarr for cohabiting couples, use year
	local fe "i.statefip i.year "
	
	local full "`demog' `imm' `fe' "


	
	*full control
	
	foreach controlgr of varlist controlgrdaca {
							
		foreach depvar of varlist cohabit_cit_sp {
		
				
			display ""
			display "--------------------------------------"
			display "Control group: `controlgr'"
			display "Dependent Variable: `depvar' "
			
			
			display "--------------------------------------"
		
			*use ib.var to set the base year
		
			reg `depvar' ib2011.year##i.treatgr `full' if daca==1|`controlgr'==1 [pweight=perwt], cluster(statefip)	
			est sto a1
			
			local coefinter 2008.year#1.treatgr  2009.year#1.treatgr ///
							2010.year#1.treatgr  2011.year#1.treatgr ///
							2012.year#1.treatgr      					  ///
							2013.year#1.treatgr  2014.year#1.treatgr ///
							2015.year#1.treatgr  2016.year#1.treatgr ///
							2017.year#1.treatgr  2018.year#1.treatgr ///
							2019.year#1.treatgr  

			coefplot, keep(`coefinter') ///
				coeflabels( 2008.year#1.treatgr = "2008"  ///
							2009.year#1.treatgr = "2009"  ///
							2010.year#1.treatgr = "2010"  ///
							2011.year#1.treatgr = "2011"   ///
							2012.year#1.treatgr = "2012"  ///
							2013.year#1.treatgr = "2013" ///
							2014.year#1.treatgr = "2014" ///
							2015.year#1.treatgr = "2015" ///
							2016.year#1.treatgr = "2016" ///
							2017.year#1.treatgr = "2017" ///
							2018.year#1.treatgr = "2018" ///
							2019.year#1.treatgr=  "2019") ///		 
					vertical 							 ///
					yline(0)							 ///
					xline(5, lpattern(dash))			///
					ytitle("Coefficient")				///
					xtitle("Year") ///
					addplot(line @b @at)				///
					ciopts(recast(rcap))				///
					/*rescale(100)*/						///
					omitted baselevels			 /*keep the baseline in the graph*/	
			
		graph export "figure3.png", replace
	
		}

	}
	

	
